/**
 *
 * @description: 路由
 * @author: junyong.hong
 * @createTime: 2018/11/20
 * @version: 1.0.0.0
 * @history:
 *    1、
 *    2、
 *
 */
const Wechat = require('../app/controllers/wechat.controller')
const User = require('../app/controllers/user.controller')
const Index = require('../app/controllers/index.controller')
const Category = require('../app/controllers/Category.controller')
const Movie = require('../app/controllers/Movie.controller')
const Comment = require('../app/controllers/Comment.controller')
// 识别文件（file）
const koaBody = require('koa-body')

module.exports = router => {
    // 首页
    router.get('/', Index.homePage)
    router.get('/sdk', Wechat.sdk)

    // 搜索
    router.get('/results', Movie.search)

    // 评论
    router.post('/comment', User.signinRequired, Comment.save)

    // 电影详情页面
    router.get('/movie/:_id', Movie.detail)

    // 用户的注册登录路由
    router.get('/user/signup', User.showSignup)
    router.get('/user/signin', User.showSignin)
    router.post('/user/signup', User.signup)
    router.post('/user/signin', User.signin)
    router.get('/user/logout', User.logout)

    // 后台的用户列表页(用户需登录，并且为管理员)
    router.get('/admin/user/list', User.signinRequired, User.adminRequired, User.list)
    router.delete('/admin/user', User.signinRequired, User.adminRequired, User.del)

    // 后台的分类管理页面
    router.get('/admin/category', User.signinRequired, User.adminRequired, Category.show)
    router.post('/admin/category', User.signinRequired, User.adminRequired, Category.new)
    router.get('/admin/category/list', User.signinRequired, User.adminRequired, Category.list)
    router.get('/admin/category/update/:_id', User.signinRequired, User.adminRequired, Category.show)
    router.delete('/admin/category', User.signinRequired, User.adminRequired, Category.del)

    // 后台的电影管理页面
    router.get('/admin/movie', User.signinRequired, User.adminRequired, Movie.show)
    router.post('/admin/movie', User.signinRequired, User.adminRequired, koaBody({ multipart: true }), Movie.savePoster, Movie.new)
    router.get('/admin/movie/list', User.signinRequired, User.adminRequired, Movie.list)
    router.get('/admin/movie/update/:_id', User.signinRequired, User.adminRequired, Movie.show)
    router.delete('/admin/movie', User.signinRequired, User.adminRequired, Movie.del)

    // 进入微信消息中间件
    router.get('/wx-hear', Wechat.hear)
    router.post('/wx-hear', Wechat.hear)

    // 异步处理网页的签名
    router.post('/wechat/signature', Wechat.getSDKSignature)

    // 跳到授权中间服务页面
    router.get('/wx-oauth', Wechat.oauth)
    // 通过code获取用户信息  http://hjyvuessr.free.idcfengye.com/userinfo
    router.get('/userinfo', Wechat.userinfo)
}